﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.GERP.GAMS.MODEL;
using KPIS.DBM;
using System.Data;
using System.Configuration;
namespace KPIS.GERP.GAMS.DAL
{
    public class D_ACM_ICM_Depreciate
    {
        DBManager dbManager = new DBManager(SystemInfo._DataProvider, ConfigurationSettings.AppSettings["ConnectionString"].ToString());
        ConvertNullable cn = new ConvertNullable();


        public IList<M_ACM_ICM_Depreciate> GetList()
        {
            DataRowCollection drc = null;
            IList<M_ACM_ICM_Depreciate> infolist = new List<M_ACM_ICM_Depreciate>();

            try
            {
                dbManager.Open();
                string strsql = "select AssetId,CalculatedDate,DepAmount,TranGrpId,UpdatedWhen"
                                + "FROM IcmAssetDepreciation ";
                drc = dbManager.ExecuteDataSet(CommandType.Text, strsql).Tables[0].Rows;
                if (drc.Count>0)
                {
                    for (int i = 0; i <= drc.Count; i++)
                    {
                        M_ACM_ICM_Depreciate info = new M_ACM_ICM_Depreciate();
                        info.AssetId = Convert.ToInt32(drc[i]["AssetId"]);
                        info.CalculateDate = Convert.ToDateTime(drc[i]["CalculateDate"]);
                        info.DepAmount = Convert.ToDecimal(drc[i]["DepAmount"]);
                        info.UpdatedWhen=Convert.ToDateTime(drc[i]["UpdatedWhen"]);
                        infolist.Add(info);
                    }
                }

             }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }
            return infolist;
        }
        public void Insert_DB_CR(M_ACM_ICM_Depreciate info)//acm_transection_dtls
        {
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(6);
                dbManager.AddParameters(0, "@AssetId", info.AssetId);
                dbManager.AddParameters(1, "@CalculateDate", info.CalculateDate);
                dbManager.AddParameters(2, "@DepAmount", info.DepAmount);
                dbManager.AddParameters(3, "@TranGrpId", info.TranGrpId);
                dbManager.AddParameters(4, "@UpdatedBy", info.UpdatedBy);
                dbManager.AddParameters(5, "@UpdatedWhen", info.UpdatedWhen);
            

                strSQL = " INSERT INTO acm_transection_dtls "
                        + "(AssetId,CalculateDate,DepAmount,TranGrpId,UpdatedBy,UpdatedWhen)"
                        + " VALUES (@AssetId,@CalculateDate,@DepAmount,@TranGrpId,@UpdatedBy,@UpdatedWhen) ";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }
        }


    }
}
